<template>
  <div>
    <h1>订单列表</h1>
    <div>
      <el-input
        placeholder="请输入查找的订单ID"
        prefix-icon="el-icon-search"
        v-model="find"
        clearable
        style="width: 300px"
      >
      </el-input>
      <el-button type="primary" icon="el-icon-search" @click="search()"
        >搜索</el-button
      >
    </div>
    <el-table :data="rows" style="width: 100%" height="250">
      <el-table-column fixed prop="_id" label="订单ID" width="250">
      </el-table-column>
      <el-table-column
        prop="userId.username"
        label="用户名"
        width="120"
      ></el-table-column>
      <el-table-column prop="shopId.name" label="门店名" width="250">
      </el-table-column>
      <el-table-column prop="goodsArr" label="商品" width="250">
        <template slot-scope="scope">
          {{ scope.row.goodsArr.map((item) => item.name).join(",") }}
        </template>
      </el-table-column>
      <el-table-column prop="price" label="总价" width="120"> </el-table-column>
      <el-table-column prop="distributionId.name" label="配送人员" width="120">
      </el-table-column>
      <el-table-column prop="time" label="下单时间" width="250">
      </el-table-column>
      <el-table-column prop="state" label="订单状态" width="120">
        <template slot-scope="scope">
          {{ getState(scope.row.state) }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="curpage"
      :page-size="eachPage"
      layout=" prev, pager, next"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers("order");
export default {
  computed: {
    ...mapState(["rows", "total", "curpage", "eachPage", "maxPage"]),
  },
  mounted() {
    this.get();
  },
  methods: {
    ...mapActions(["get", "searchOrder"]),
    ...mapMutations(["setCurPage"]),
    getState(state) {
      return state ? "已完成" : "进行中";
    },
    search() {
      const searchID = this.$data.find;
      this.searchOrder({ searchID });
      this.$data.find="";
    },
    handleCurrentChange(val) {
      this.setCurPage(val);
    },
  },
  data() {
    return {
      find: "",
    };
  },
  watch: {
    curpage() {
      this.get();
    },
  },
};
</script>

<style></style>
